package com.centriole.service.workflow.enums;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**状态类型枚举类
 * @author 吴凯
 *
 */
public enum StateType {
	NODEPLOY("0", "未部署"),
	DEPLOYED("1","已部署"),
	STOP("2","已暂停"),
	COVERED("3","被覆盖"),
	NOT_SUBMITTED("4","未提交"),
	APPROVAL_RUN("5","审批中"),
	APPROVAL_YES("6","通过"),
	APPROVAL_NO("7","未通过"),
	NORMAL("8","正常"),
	DELETE("9","已删除");
	
	private StateType(String statusCode, String statusName) {
		this.statusCode = statusCode;
		this.statusName = statusName;
	}
	
	String statusCode;
	
	String statusName;
	
	public String statusCode() {
		return statusCode;
	}
	
	public String statusName() {
		return statusName;
	}
	
	/**根据Code获取Name
	 * @param code
	 * @return
	 */
	public static String getNameByCode(String code){
		for (StateType status: StateType.values()) {
	        if (status.statusCode.equals(code))
	            return status.statusName;
	    }
	    return null;
	}
	/**获取流程状态类型
	 * @return
	 */
	public static JSONArray getActStateType(){
		JSONArray arr = new JSONArray();
		JSONObject obj = new JSONObject();
		obj.put("text", NODEPLOY.statusName());
		obj.put("value", NODEPLOY.statusCode());
		arr.add(obj);
		obj.put("text", DEPLOYED.statusName());
		obj.put("value", DEPLOYED.statusCode());
		arr.add(obj);
		obj.put("text", STOP.statusName());
		obj.put("value", STOP.statusCode());
		arr.add(obj);
		obj.put("text", DELETE.statusName());
		obj.put("value", DELETE.statusCode());
		arr.add(obj);
		return arr;
	}
	
	/**获取普通状态类型
	 * @return
	 */
	public static JSONArray getStateType(){
		JSONArray arr = new JSONArray();
		JSONObject obj = new JSONObject();
		obj.put("text", NORMAL.statusName());
		obj.put("value", NORMAL.statusCode());
		arr.add(obj);
		obj.put("text", DELETE.statusName());
		obj.put("value", DELETE.statusCode());
		arr.add(obj);
		return arr;
	}
}
